package com.kbt.fragment;


import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.util.DisplayMetrics;
import android.view.*;
import android.widget.*;
import com.android.volley.Request;
import com.kbt.activity.*;
import com.kbt.commont.Constants;
import com.kbt.model.data.*;
import com.kbt.model.holder.NewGoodItemHolder;
import com.kbt.net.RequestManager;
import com.kbt.testimageview.RollViewPager;
import com.kbt.util.data.StaticData;
import com.kbt.util.tool.BtnSetting;
import com.kbt.util.tool.RestListViewSizeTool;
import com.kbt.util.utils.ImageManager;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.kbt.util.utils.LoadingDialog;
import com.kbt.util.utils.SetingImage;
import com.kbt.util.utils.Utils;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author zhanggk
 * @Description 主页面的容器
 * @date 15/7/31.
 */
public class HomeFragment extends Fragment implements RequestManager.ResponseInterface{
    //轮播图
    private TeMaiAndKaiQiangListBean lunboListBean;
    private List<TeMaiAndKaiQiangBean> lunboBeans = new ArrayList<TeMaiAndKaiQiangBean>();

    //热销
    private SellingListBean sellingListBean;
    private List<SellingBean> sellingBeans = new ArrayList<SellingBean>();
   //特卖
    private TeMaiAndKaiQiangListBean teMaiAndKaiQiangListBean;
    private List<TeMaiAndKaiQiangBean> teMaiAndKaiQiangBeans = new ArrayList<TeMaiAndKaiQiangBean>();

    private RequestManager mRequestManager;

    GridView gridView;
    /***
     * 新上商品定义
     * 定义端品列表
     * 商品明辔
     * *********/
    ListView listView;
    private TextView teMai;
    private TextView kaiQiang;
    private View teMai_view;
    private View kaiqiang_view;
    private Map<String,Object> map;


    //轮播
    private ArrayList<View> dots = null;
    private LinearLayout mViewPagerLay;// 只需要一个layout即可,ViewPager是动态加载的
    private ArrayList<String> uriList = null;
    private ImageView dot_0;
    private ImageView dot_1;
    private ImageView dot_2;
    private ImageView dot_3;
    private ImageView dot_4;
    private ImageView dot_5;
    private ImageView dot_6;
    private ImageView dot_7;
    private ImageView dot_8;
    private ImageView dot_9;
    private RollViewPager mViewPager;

    private LoadingDialog mProgress;

    private long hours;
    private long minutes;
    private long seconds;
    private long diff;
    private long days;
    private long haomiao;



    private List<Goods> goodss = new ArrayList<Goods>();
    private NewGoodListAdapter goodAdapter;//特卖
    private KaiQiangAdapter kaiQiangAdapter;//开抢
    private TeMaiAndKQHandler teMaiKQHandler;

    private View view;

    //分类图标
    private FenLeiListBean fenLeiListBean;
    private List<FenLeiBean> fenLeiBeans = new ArrayList<FenLeiBean>();

    /**
     * @project: kbt
     * @package: com.kbt.ui
     * @class:
     * @Desc:MessageHandler用于更新主界面
     * @author: kuajie
     * @time: 15/8/1 11:19
     * @Version: 1.0
     */

    private Handler titleImgHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
             if (msg.what == StaticData.SHOUYE_VIEWPAGER_FLAG) {
                 //获取分类图标
                 httpFenLeiImage();
                 initHotTitleSotre();
            }

        }
    };




    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view =inflater.inflate(R.layout.index_layout, container, false);

        //初始化ImageLoader
        ImageManager.init();
        //初始化请求的管理器
        mRequestManager = new RequestManager();
        mRequestManager.setResponseListener(this);
        map = new HashMap<String, Object>();
        httpTopImage();
        return view;
    }

    /**
     * @desc： 重写onStart()方法
     * @param: null
     * @return: void
     * @author: zhanggk
     * @date: 2015-07-31
     */
    @Override
    public void onStart() {
        super.onStart();
    }
    private void init(){
        //初始化热销商品
        initHotStore();
        //初始化新上市商品
        initNewGoods();
    }
    //分类图标
    private void httpFenLeiImage(){
        showProgress();
        if(Utils.isNetworkAvailable(getActivity())) {
            mRequestManager.requestGet(Request.Method.GET, Constants.ServiceInterFace.selectFenleiImageURL, Constants.RequestTag.selectFenLeiImageTag, map, FenLeiListBean.class);
        }else {
            stopProgress();
            Toast.makeText(getActivity(), R.string.Wangluo, Toast.LENGTH_SHORT).show();
        }
    }
    //分类图标
    private void initFenLeiImage(){
        LinearLayout tubiao = (LinearLayout) getView().findViewById(R.id.tubiao);
        LinearLayout tubiao2 = (LinearLayout) getView().findViewById(R.id.tubiao2);
        tubiao.removeAllViews();
        tubiao2.removeAllViews();
        if(fenLeiBeans.size()>6) {
            int number = fenLeiBeans.size()/2;
            tubiao2.setVisibility(View.VISIBLE);
            for (int i = 0; i < number; i++) {
                LinearLayout linearLayout = new LinearLayout(getActivity());
                LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                        ViewGroup.LayoutParams.WRAP_CONTENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT,
                        1
                );
                linearLayout.setOrientation(LinearLayout.VERTICAL);
                linearLayout.setPadding(5, 5, 5, 5);
                linearLayout.setGravity(Gravity.CENTER);
                linearLayout.setLayoutParams(params);

                ImageView imageView = new ImageView(getActivity());
                imageView.setAdjustViewBounds(true);


                LinearLayout.LayoutParams image = new LinearLayout.LayoutParams(
                        ViewGroup.LayoutParams.WRAP_CONTENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT
                );
                imageView.setId(Integer.parseInt(fenLeiBeans.get(i).getFl_code()));
                imageView.setTag(fenLeiBeans.get(i).getFl_name());
                imageView.setLayoutParams(image);
                imageView.setPadding(6, 6, 6, 6);

                String url = fenLeiBeans.get(i).getFl_icon();
                int screenWidth=0;
                if(getActivity()!=null){
                    screenWidth =getActivity().getWindowManager().getDefaultDisplay().getWidth()/8-10;
                }
                ViewGroup.LayoutParams lp = imageView.getLayoutParams();
                lp.width = screenWidth;

                String[] url_params = url.split("&");
                int imageWidth = 0;
                int imageHeight = 0;
                if(url_params.length == 3){
                    imageWidth = Integer.parseInt(url_params[1].split("=")[1]);
                    imageHeight = Integer.parseInt(url_params[2].split("=")[1]);
                }

                if(imageWidth>0 && imageHeight>0){
                    lp.height = new Float(imageHeight*screenWidth/imageWidth).intValue();
                }else{
                    lp.height = ViewGroup.LayoutParams.MATCH_PARENT;
                }
                imageView.setLayoutParams(lp);
                imageView.setMaxWidth(screenWidth);
                imageView.setMaxHeight(screenWidth *10);
//                imageView.setImageResource(R.drawable.fl_aj);
                ImageManager.imageLoader.displayImage(Constants.ServiceInterFace.imageURL + fenLeiBeans.get(i).getFl_icon(), imageView, ImageManager.getOptions(
                        R.drawable.loadings, R.drawable.loadings));
                TextView textView = new TextView(getActivity());
                LinearLayout.LayoutParams textview = new LinearLayout.LayoutParams(
                        ViewGroup.LayoutParams.WRAP_CONTENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT
                );
                textView.setBottom(5);
                textView.setTextSize(10);
                textView.setLayoutParams(textview);
                textView.setText(fenLeiBeans.get(i).getFl_name());
                imageView.setOnClickListener(new TabOnClickLinstener());
                linearLayout.addView(imageView);
                linearLayout.addView(textView);
                tubiao.addView(linearLayout);
            }

            for (int i = number; i < fenLeiBeans.size(); i++) {
                LinearLayout linearLayout = new LinearLayout(getActivity());
                LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                        ViewGroup.LayoutParams.WRAP_CONTENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT,
                        1
                );
                linearLayout.setOrientation(LinearLayout.VERTICAL);
                linearLayout.setPadding(5, 5, 5, 5);
                linearLayout.setGravity(Gravity.CENTER);
                linearLayout.setLayoutParams(params);

                ImageView imageView = new ImageView(getActivity());
                LinearLayout.LayoutParams image = new LinearLayout.LayoutParams(
                        ViewGroup.LayoutParams.WRAP_CONTENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT
                );
                imageView.setId(Integer.parseInt(fenLeiBeans.get(i).getFl_code()));
                imageView.setTag(fenLeiBeans.get(i).getFl_name());
                imageView.setLayoutParams(image);
                imageView.setPadding(6, 6, 6, 6);

                String url = fenLeiBeans.get(i).getFl_icon();
                int screenWidth=0;
                if(getActivity()!=null){
                    screenWidth =getActivity().getWindowManager().getDefaultDisplay().getWidth()/8-10;
                }
                ViewGroup.LayoutParams lp = imageView.getLayoutParams();
                lp.width = screenWidth;

                String[] url_params = url.split("&");
                int imageWidth = 0;
                int imageHeight = 0;
                if(url_params.length == 3){
                    imageWidth = Integer.parseInt(url_params[1].split("=")[1]);
                    imageHeight = Integer.parseInt(url_params[2].split("=")[1]);
                }

                if(imageWidth>0 && imageHeight>0){
                    lp.height = new Float(imageHeight*screenWidth/imageWidth).intValue();
                }else{
                    lp.height = ViewGroup.LayoutParams.MATCH_PARENT;
                }
                imageView.setLayoutParams(lp);
                imageView.setMaxWidth(screenWidth);
                imageView.setMaxHeight(screenWidth *10);
                ImageManager.imageLoader.displayImage(Constants.ServiceInterFace.imageURL + fenLeiBeans.get(i).getFl_icon(), imageView, ImageManager.getOptions(
                        R.drawable.loadings, R.drawable.loadings));

                TextView textView = new TextView(getActivity());
                LinearLayout.LayoutParams textview = new LinearLayout.LayoutParams(
                        ViewGroup.LayoutParams.WRAP_CONTENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT
                );
                textView.setBottom(5);
                textView.setTextSize(10);
                textView.setLayoutParams(textview);
                textView.setText(fenLeiBeans.get(i).getFl_name());
                imageView.setOnClickListener(new TabOnClickLinstener());
                linearLayout.addView(imageView);
                linearLayout.addView(textView);
                tubiao2.addView(linearLayout);
            }
        }else{
            for (int i = 0; i < fenLeiBeans.size(); i++) {
                LinearLayout linearLayout = new LinearLayout(getActivity());
                LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                        ViewGroup.LayoutParams.WRAP_CONTENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT,
                        1
                );
                linearLayout.setOrientation(LinearLayout.VERTICAL);
                linearLayout.setPadding(5, 5, 5, 5);
                linearLayout.setGravity(Gravity.CENTER);
                linearLayout.setLayoutParams(params);

                ImageView imageView = new ImageView(getActivity());
                LinearLayout.LayoutParams image = new LinearLayout.LayoutParams(
                        ViewGroup.LayoutParams.WRAP_CONTENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT
                );
                imageView.setId(Integer.parseInt(fenLeiBeans.get(i).getFl_code()));
                imageView.setTag(fenLeiBeans.get(i).getFl_name());
                imageView.setLayoutParams(image);
                imageView.setPadding(6, 6, 6, 6);

                String url = fenLeiBeans.get(i).getFl_icon();

                int screenWidth =getActivity().getWindowManager().getDefaultDisplay().getWidth()/8-10;
                ViewGroup.LayoutParams lp = imageView.getLayoutParams();
                lp.width = screenWidth;

                String[] url_params = url.split("&");
                int imageWidth = 0;
                int imageHeight = 0;
                if(url_params.length == 3){
                    imageWidth = Integer.parseInt(url_params[1].split("=")[1]);
                    imageHeight = Integer.parseInt(url_params[2].split("=")[1]);
                }

                if(imageWidth>0 && imageHeight>0){
                    lp.height = new Float(imageHeight*screenWidth/imageWidth).intValue();
                }else{
                    lp.height = ViewGroup.LayoutParams.MATCH_PARENT;
                }
                imageView.setLayoutParams(lp);
                imageView.setMaxWidth(screenWidth);
                imageView.setMaxHeight(screenWidth *10);
//                imageView.setImageResource(R.drawable.fl_aj);
                ImageManager.imageLoader.displayImage(Constants.ServiceInterFace.imageURL + fenLeiBeans.get(i).getFl_icon(), imageView, ImageManager.getOptions(
                        R.drawable.loadings, R.drawable.loadings));

                TextView textView = new TextView(getActivity());
                LinearLayout.LayoutParams textview = new LinearLayout.LayoutParams(
                        ViewGroup.LayoutParams.WRAP_CONTENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT
                );
                textView.setBottom(5);
                textView.setTextSize(10);
                textView.setLayoutParams(textview);
                textView.setText(fenLeiBeans.get(i).getFl_name());
                imageView.setOnClickListener(new TabOnClickLinstener());
                linearLayout.addView(imageView);
                linearLayout.addView(textView);
                tubiao.addView(linearLayout);
            }
        }
    }

    private class TabOnClickLinstener implements View.OnClickListener{
        @Override
        public void onClick(View v) {
                Intent intent = new Intent(getActivity(), NewGoodsListActivity.class);
                intent.putExtra("tag",(v.getId())+"");
                intent.putExtra("name",(v.getTag())+"");
                startActivity(intent);
        }
    }


    /**
     * 初始化头部热门商品
     **/
    private void initHotTitleSotre() {
        initUI();
        initData();
        init();

    }
    /**
     * @description: 初始化热门商品，用于横向展示
     * @param: null
     * @return:void
     * @author:zhanggk
     * @date:2015-08-04
     * ****/
    private void initHotStore() {
        gridView = (GridView) getView().findViewById(R.id.grid);
        setGridViewData();
    }


    //请求数据
    private void httpTopImage(){
        showProgress();
        if(Utils.isNetworkAvailable(getActivity())) {
            mRequestManager.requestGet(Request.Method.GET, Constants.ServiceInterFace.zuanZhanURL, Constants.RequestTag.zuanZhanTag, map, TeMaiAndKaiQiangListBean.class);
        }else {
            stopProgress();
            Toast.makeText(getActivity(), R.string.Wangluo, Toast.LENGTH_SHORT).show();
        }
    }

    /**
     * @description:设置横向展示数据
     * @param: null
     * @return:void
     * @author:zhanggk
     * @date:2015-08-04
     ****/
    private void setGridViewData() {
        showProgress();
        //获取热销商品数据
        if(Utils.isNetworkAvailable(getActivity())) {
            mRequestManager.requestGet(Request.Method.GET, Constants.ServiceInterFace.sellingURL, Constants.RequestTag.sellingTag, map, SellingListBean.class);
        }else {
            stopProgress();
            Toast.makeText(getActivity(),R.string.Wangluo,Toast.LENGTH_SHORT).show();
        }
    }

    /**
     * @description: 设置GridView用于横向展示
     * @param: null
     * @return:void
     * @author:zhanggk
     * @date:2015-08-04
     ****/
    private void setGridView() {

        //点击背景不变颜色
        gridView.setSelector(new ColorDrawable(Color.TRANSPARENT));

        int size = sellingBeans.size();
        int length = 100;
        DisplayMetrics dm=null;
        if(dm==null) {
            dm = new DisplayMetrics();
        }
        if(this.getActivity()!=null){
            this.getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
        }
        float density = dm.density;
        int gridviewWidth = (int) (size * (length + 6) * density);
        int itemWidth = (int) (length * density);


        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                gridviewWidth, LinearLayout.LayoutParams.MATCH_PARENT);
        gridView.setLayoutParams(params); // 设置GirdView布局参数,横向布局的关键
        gridView.setColumnWidth(itemWidth); // 设置列表项宽
        gridView.setStretchMode(GridView.NO_STRETCH);
        gridView.setNumColumns(size); // 设置列数量=列表集合数

        GridViewAdapter adapter = new GridViewAdapter(getActivity().getApplicationContext(), sellingBeans);
        gridView.setAdapter(adapter);
        //设置GridView的单击事件
        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    Intent goodInfo = new Intent(getActivity(), GoodInfoActivity.class);
                    goodInfo.putExtra("shopId",sellingBeans.get(position).getGoods_id()+"");
                    startActivity(goodInfo);
                }

        });


    }

    /**
     * @description: 初始化新上市商品用于纵向展示
     * @param: null
     * @return:void
     * @author:zhanggk
     * @date:2015-08-04
     ****/
    private void initNewGoods() {
        listView = (ListView) getView().findViewById(R.id.newGoodsListView);
        teMai = (TextView) getView().findViewById(R.id.teMai);
        kaiQiang = (TextView) getView().findViewById(R.id.kaiQiang);
        teMai_view = getView().findViewById(R.id.teMai_view);
        kaiqiang_view = getView().findViewById(R.id.kaiqiang_view);
        initListener();
        httpTeMai();
    }

    //请求特卖数据
    private void httpTeMai(){
        showProgress();
        if(Utils.isNetworkAvailable(getActivity())) {
            mRequestManager.requestGet(Request.Method.GET, Constants.ServiceInterFace.teMaiURL, Constants.RequestTag.teMaiTag, map, TeMaiAndKaiQiangListBean.class);
        }else{
            stopProgress();
            Toast.makeText(getActivity(),R.string.Wangluo,Toast.LENGTH_SHORT).show();
        }
    }
    //请求开抢数据
    private void httpKaiQiang(){
        showProgress();
        if(Utils.isNetworkAvailable(getActivity())) {
            mRequestManager.requestGet(Request.Method.GET, Constants.ServiceInterFace.kaiQiangURL, Constants.RequestTag.kaiQiangTag, map, TeMaiAndKaiQiangListBean.class);
        }else{
            stopProgress();
            Toast.makeText(getActivity(),R.string.Wangluo,Toast.LENGTH_SHORT).show();
        }
    }
    private void initListener(){
        teMai.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                httpTeMai();
                teMai.setTextColor(Color.RED);
                kaiQiang.setTextColor(Color.rgb(101,101,101));
                teMai_view.setBackgroundColor(Color.RED);
                kaiqiang_view.setBackgroundColor(Color.rgb(238,238,238));
            }
        });
        kaiQiang.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                httpKaiQiang();
                teMai.setTextColor(Color.rgb(101, 101, 101));
                kaiQiang.setTextColor(Color.RED);
                teMai_view.setBackgroundColor(Color.rgb(238,238,238));
                kaiqiang_view.setBackgroundColor(Color.RED);
            }
        });
    }

    //特卖
    private void setteMaiBeansView() {
        if(teMaiKQHandler==null) {
            teMaiKQHandler = new TeMaiAndKQHandler();
        }
        goodss.clear();
        for(int i=0;i<teMaiAndKaiQiangBeans.size();i++){
            goodss.add(new Goods(getTime(getNewTime(),teMaiAndKaiQiangBeans.get(i).getEnd_time()+":000")));
        }
        listView.setDividerHeight(4);
        if(goodAdapter==null) {
            goodAdapter = new NewGoodListAdapter(getActivity(),
                    teMaiAndKaiQiangBeans);
        }
        goodAdapter.setList(teMaiAndKaiQiangBeans);
        listView.setAdapter(goodAdapter);
        RestListViewSizeTool.setListViewHeightBasedOnChildren(listView);
        teMaiKQHandler.removeMessages(1);
        teMaiKQHandler.removeMessages(2);
        teMaiKQHandler.sendEmptyMessage(1);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent(getActivity(), TeMaiKaiQiangActivity.class);
                intent.putExtra("active_id",teMaiAndKaiQiangBeans.get(position).getActive_id());
                intent.putExtra("active_desc",teMaiAndKaiQiangBeans.get(position).getActive_desc());
                intent.putExtra("active_icon",teMaiAndKaiQiangBeans.get(position).getActive_icon());
                intent.putExtra("startTime",teMaiAndKaiQiangBeans.get(position).getStart_time());
                intent.putExtra("endTime",teMaiAndKaiQiangBeans.get(position).getEnd_time());
                intent.putExtra("title",teMaiAndKaiQiangBeans.get(position).getActive_right_title());
                startActivity(intent);
            }
        });

    }
    //开抢
    private void setKaiQiangBeansView() {
        if(teMaiKQHandler==null) {
            teMaiKQHandler = new TeMaiAndKQHandler();
        }
        goodss.clear();
        for(int i=0;i<teMaiAndKaiQiangBeans.size();i++){
            goodss.add(new Goods(getTime(getNewTime(), teMaiAndKaiQiangBeans.get(i).getStart_time()+":000")));
        }
        listView.setDividerHeight(4);
        if(kaiQiangAdapter==null) {
            kaiQiangAdapter = new KaiQiangAdapter(this.getActivity().getApplicationContext(),
                    teMaiAndKaiQiangBeans);
        }
        kaiQiangAdapter.setList(teMaiAndKaiQiangBeans);
        listView.setAdapter(kaiQiangAdapter);
        RestListViewSizeTool.setListViewHeightBasedOnChildren(listView);
        teMaiKQHandler.removeMessages(2);
        teMaiKQHandler.removeMessages(1);
        teMaiKQHandler.sendEmptyMessage(2);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent(getActivity(), TeMaiKaiQiangActivity.class);
                intent.putExtra("active_id",teMaiAndKaiQiangBeans.get(position).getActive_id());
                intent.putExtra("active_desc",teMaiAndKaiQiangBeans.get(position).getActive_desc());
                intent.putExtra("active_icon",teMaiAndKaiQiangBeans.get(position).getActive_icon());
                intent.putExtra("startTime",teMaiAndKaiQiangBeans.get(position).getStart_time());
                intent.putExtra("endTime",teMaiAndKaiQiangBeans.get(position).getEnd_time());
                intent.putExtra("title",teMaiAndKaiQiangBeans.get(position).getActive_right_title());
                intent.putExtra("tag","kaiQiang");
                startActivity(intent);
            }
        });

    }

    @Override
    public <T> void successResponse(T parsedGSON, int tag) {
        stopProgress();
        if (tag == Constants.RequestTag.zuanZhanTag) {
            /** 判断返回值不为空 **/
            if (parsedGSON != null) {
                lunboListBean = (TeMaiAndKaiQiangListBean) parsedGSON;
                // 判断是否是有数据
                if (lunboListBean.getResult().equals("success")) {// 成功
                    if (lunboListBean.getData().size()>0) {//获取到数据
                        lunboBeans = lunboListBean.getData();
                        Message msg = new Message();
                        msg.what = StaticData.SHOUYE_VIEWPAGER_FLAG;
                        titleImgHandler.sendMessage(msg);

                    }
                }
            }
        }
        if (tag == Constants.RequestTag.sellingTag) {
            if (parsedGSON != null) {
                sellingListBean = (SellingListBean) parsedGSON;
                // 判断是否是有数据
                if (sellingListBean.getResult().equals("success")){
                    if(sellingListBean.getData().size()>0){
                       sellingBeans =sellingListBean.getData();
                       setGridView();
                    }
                }
            }
        }
        if (tag == Constants.RequestTag.teMaiTag) {
            if (parsedGSON != null) {
                teMaiAndKaiQiangListBean = (TeMaiAndKaiQiangListBean) parsedGSON;
                // 判断是否是有数据
                if (teMaiAndKaiQiangListBean.getResult().equals("success")){
                    if(teMaiAndKaiQiangListBean.getData().size()>0){
                       teMaiAndKaiQiangBeans =teMaiAndKaiQiangListBean.getData();
                        setteMaiBeansView();
                    }else{
                        teMaiAndKaiQiangBeans.clear();
                        if(goodAdapter==null) {
                            goodAdapter = new NewGoodListAdapter(getActivity(),
                                    teMaiAndKaiQiangBeans);
                        }
                        goodAdapter.setList(teMaiAndKaiQiangBeans);
                        goodAdapter.notifyDataSetChanged();
                    }
                }
            }
        }
        if (tag == Constants.RequestTag.kaiQiangTag) {
            if (parsedGSON != null) {
                teMaiAndKaiQiangListBean = (TeMaiAndKaiQiangListBean) parsedGSON;
                // 判断是否是有数据
                if (teMaiAndKaiQiangListBean.getResult().equals("success")){
                    if(teMaiAndKaiQiangListBean.getData().size()>0){
                       teMaiAndKaiQiangBeans =teMaiAndKaiQiangListBean.getData();
                        setKaiQiangBeansView();
                    }else{
                        teMaiAndKaiQiangBeans.clear();
                        if(kaiQiangAdapter==null) {
                            kaiQiangAdapter = new KaiQiangAdapter(this.getActivity().getApplicationContext(),
                                    teMaiAndKaiQiangBeans);
                        }
                        kaiQiangAdapter.setList(teMaiAndKaiQiangBeans);
                        kaiQiangAdapter.notifyDataSetChanged();
                    }
                }
            }
        }
        if (tag == Constants.RequestTag.selectFenLeiImageTag) {
            if (parsedGSON != null) {
                fenLeiListBean = (FenLeiListBean) parsedGSON;
                // 判断是否是有数据
                if (fenLeiListBean.getResult().equals("success")){
                    if(fenLeiListBean.getData().size()>0){
                       fenLeiBeans =fenLeiListBean.getData();
                        initFenLeiImage();
                    }
                }
            }
        }
    }

    @Override
    public void errorResonse(String retmeg, int tag) {
        stopProgress();
        Toast.makeText(getActivity(), R.string.noWangluo, Toast.LENGTH_SHORT).show();
    }


    /**
     * @description: GridView的适配数据
     * @param: null
     * @return:void
     * @author:zhanggk
     * @date:2015-08-04
     * ****/
    private class GridViewAdapter extends BaseAdapter{
        Context context;
        List<SellingBean> list;

        public GridViewAdapter(Context _context, List<SellingBean> _list) {
            this.list = _list;
            this.context = _context;
        }

        @Override
        public int getCount() {
            return list.size();
        }

        @Override
        public Object getItem(int position) {
            return list.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            LayoutInflater layoutInflater = LayoutInflater.from(context);
            convertView = layoutInflater.inflate(R.layout.index_hot_good_item, null);
            LinearLayout zuiReLin= (LinearLayout) convertView.findViewById(R.id.zuiReLin);
            ImageView imgView = (ImageView)convertView.findViewById(R.id.tvImage);
            TextView tvCity = (TextView) convertView.findViewById(R.id.tvCity);
            TextView tvCode = (TextView) convertView.findViewById(R.id.tvCode);
            SellingBean selling = list.get(position);
            BtnSetting.setLinBackground(zuiReLin, 0, Color.WHITE, Color.WHITE, 15);
            tvCity.setText(selling.getGoods_title());
            tvCode.setText("￥"+selling.getGoods_new_price());
            ImageManager.imageLoader.displayImage(Constants.ServiceInterFace.imageURL + selling.getGoods_icon(), imgView, ImageManager.getOptions(
                    R.drawable.loadings, R.drawable.loadings));
            return convertView;
        }
    }
    //特卖
    private class NewGoodListAdapter extends BaseAdapter{
        Context context;
        List<TeMaiAndKaiQiangBean> list;

        public NewGoodListAdapter(Context _context, List<TeMaiAndKaiQiangBean> _list) {
            this.list = _list;
            this.context = _context;
        }

        @Override
        public int getCount() {
            return list.size();
        }

        @Override
        public Object getItem(int position) {
            return list.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }
        /**
         * 再次赋值
         *
         * @param mlist
         */
        public void setList(List<TeMaiAndKaiQiangBean> mlist) {
            list = mlist;
        }


        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            Goods goods = goodss.get(position);
            NewGoodItemHolder itemHolder;
            if(convertView == null){
                itemHolder = new NewGoodItemHolder();
                LayoutInflater layoutInflater = LayoutInflater.from(context);
                convertView = layoutInflater.inflate(R.layout.index_new_goods_item, null);
                itemHolder.setNewGoodImag( (ImageView)convertView.findViewById(R.id.newGoodImg));
                itemHolder.setNewGoodLab((TextView) convertView.findViewById(R.id.newGoodLab));
                itemHolder.setNewGoodTitle((TextView) convertView.findViewById(R.id.newGooTitle));
                itemHolder.setTime((TextView) convertView.findViewById(R.id.time));
                convertView.setTag(itemHolder);
            }else{
                itemHolder = (NewGoodItemHolder)convertView.getTag();
            }

            TeMaiAndKaiQiangBean bean = teMaiAndKaiQiangBeans.get(position);

            String url = bean.getActive_icon();
            int screenWidth=0;
            if(getActivity()!=null) {
                screenWidth = getActivity().getWindowManager().getDefaultDisplay().getWidth();
            }
            ViewGroup.LayoutParams lp = itemHolder.getNewGoodImag().getLayoutParams();
            lp.width = screenWidth;

            String[] url_params = url.split("&");
            int imageWidth = 0;
            int imageHeight = 0;
            if(url_params.length == 3){
                imageWidth = Integer.parseInt(url_params[1].split("=")[1]);
                imageHeight = Integer.parseInt(url_params[2].split("=")[1]);
            }

            if(imageWidth>0 && imageHeight>0){
                lp.height = new Float(imageHeight*screenWidth/imageWidth).intValue();
            }else{
                lp.height = ViewGroup.LayoutParams.MATCH_PARENT;
            }
            itemHolder.getNewGoodImag().setLayoutParams(lp);
            itemHolder.getNewGoodImag().setMaxWidth(screenWidth);
            itemHolder.getNewGoodImag().setMaxHeight(screenWidth *10);
            days = goods.getTime() / (1000 * 60 * 60 * 24);
            hours = (goods.getTime()-days*(1000 * 60 * 60 * 24))/(1000* 60 * 60);
            minutes = (goods.getTime()-days*(1000 * 60 * 60 * 24)-hours*(1000* 60 * 60))/(1000* 60);
            seconds = (goods.getTime()-days*(1000 * 60 * 60 * 24)-hours*(1000* 60 * 60)-minutes*(1000* 60))/(1000);
            haomiao =  (goods.getTime()-days*(1000 * 60 * 60 * 24)-hours*(1000* 60 * 60)-minutes*(1000* 60)-seconds*1000)/(100);
            itemHolder.getTime().setText("剩"+days+"天"+hours+":"+minutes+":"+seconds+":"+haomiao);
            itemHolder.getNewGoodLab().setText(""+bean.getActive_right_title());
            itemHolder.getNewGoodTitle().setText(bean.getActive_left_title());

            ImageManager.imageLoader.displayImage(Constants.ServiceInterFace.imageURL + bean.getActive_icon(), itemHolder.getNewGoodImag(), ImageManager.getOptions(
                    R.drawable.loadings, R.drawable.loadings));

            return convertView;
        }


    }
    //开抢
    private class KaiQiangAdapter extends BaseAdapter{
        Context context;
        List<TeMaiAndKaiQiangBean> list;

        public KaiQiangAdapter(Context _context, List<TeMaiAndKaiQiangBean> _list) {
            this.list = _list;
            this.context = _context;
        }

        @Override
        public int getCount() {

            return list.size();
        }

        @Override
        public Object getItem(int position) {
            return list.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }
        /**
         * 再次赋值
         *
         * @param mlist
         */
        public void setList(List<TeMaiAndKaiQiangBean> mlist) {
            list = mlist;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            Goods goods = goodss.get(position);
            NewGoodItemHolder itemHolder;
            if(convertView == null){
                itemHolder = new NewGoodItemHolder();
                LayoutInflater layoutInflater = LayoutInflater.from(context);
                convertView = layoutInflater.inflate(R.layout.index_new_goods_item, null);
                itemHolder.setNewGoodImag( (ImageView)convertView.findViewById(R.id.newGoodImg));
                itemHolder.settMKQItem((FrameLayout) convertView.findViewById(R.id.tMKQItem));
                itemHolder.setNewGoodLab((TextView) convertView.findViewById(R.id.newGoodLab));
                itemHolder.setNewGoodTitle((TextView) convertView.findViewById(R.id.newGooTitle));
                itemHolder.setTime((TextView) convertView.findViewById(R.id.time));
                itemHolder.setKaiqiang((ImageView) convertView.findViewById(R.id.kaiQiang));
                convertView.setTag(itemHolder);
            }else{
                itemHolder = (NewGoodItemHolder)convertView.getTag();
            }
            days = goods.getTime() / (1000 * 60 * 60 * 24);
            hours = (goods.getTime()-days*(1000 * 60 * 60 * 24))/(1000* 60 * 60);
            minutes = (goods.getTime()-days*(1000 * 60 * 60 * 24)-hours*(1000* 60 * 60))/(1000* 60);
            seconds = (goods.getTime()-days*(1000 * 60 * 60 * 24)-hours*(1000* 60 * 60)-minutes*(1000* 60))/(1000);
            haomiao =  (goods.getTime()-days*(1000 * 60 * 60 * 24)-hours*(1000* 60 * 60)-minutes*(1000* 60)-seconds*1000)/(100);
            itemHolder.getTime().setText(""+days+"天"+hours+":"+minutes+":"+seconds+"后开抢");
            TeMaiAndKaiQiangBean bean = teMaiAndKaiQiangBeans.get(position);

            String url = bean.getActive_icon();
            int width=0;
            if(getActivity()!=null) {
                 width = getActivity().getWindowManager().getDefaultDisplay().getWidth();
            }
            SetingImage.setImageHeightWidth(width, url, itemHolder.getNewGoodImag());

            itemHolder.getNewGoodLab().setText("" + bean.getActive_right_title());
            itemHolder.getNewGoodTitle().setText(bean.getActive_left_title());
            ImageManager.imageLoader.displayImage(Constants.ServiceInterFace.imageURL + bean.getActive_icon(), itemHolder.getNewGoodImag(), ImageManager.getOptions(
                    R.drawable.loadings, R.drawable.loadings));
            int screenWidth=0;
            if(getActivity()!=null) {
                 screenWidth = getActivity().getWindowManager().getDefaultDisplay().getWidth() / 2;
            }
            SetingImage.setImageHeightWidthTwo(screenWidth,url,itemHolder.getKaiqiang());
            itemHolder.getKaiqiang().setVisibility(View.VISIBLE);

            return convertView;
        }


    }

    private void initUI() {
        if(getView()==null){
          return;
        }
        mViewPagerLay = (LinearLayout) getView().findViewById(R.id.viewpager);
        dot_0 = (ImageView) getView().findViewById(R.id.dot_0);
        dot_1 = (ImageView) getView().findViewById(R.id.dot_1);
        dot_2 = (ImageView) getView().findViewById(R.id.dot_2);
        dot_3 = (ImageView) getView().findViewById(R.id.dot_3);
        dot_4 = (ImageView) getView().findViewById(R.id.dot_4);
        dot_5 = (ImageView) getView().findViewById(R.id.dot_5);
        dot_6 = (ImageView) getView().findViewById(R.id.dot_6);
        dot_7 = (ImageView) getView().findViewById(R.id.dot_7);
        dot_8 = (ImageView) getView().findViewById(R.id.dot_8);
        dot_9 = (ImageView) getView().findViewById(R.id.dot_9);
    }
    private void initData() {
        // 用来显示的点
        dots = new ArrayList<View>();
       // 构造网络图片
        uriList = new ArrayList<String>();
        uriList.clear();
        String imageUrl= "";
        for(int i=0;i<lunboBeans.size();i++){
            uriList.add(lunboBeans.get(i).getActive_icon());
            imageUrl = lunboBeans.get(i).getActive_icon();
        }
        RelativeLayout relative_shopInfo = (RelativeLayout) getView().findViewById(R.id.lb);
        int screenWidth=0;
        if(getActivity()!=null) {
             screenWidth = getActivity().getWindowManager().getDefaultDisplay().getWidth();
        }
        ViewGroup.LayoutParams lp = relative_shopInfo.getLayoutParams();
        lp.width = screenWidth;
        String[] url_params = imageUrl.split("&");

        int imageWidth = 0;
        int imageHeight = 0;
        if(url_params.length == 3){
            if(url_params[1].split("=").length ==2 && url_params[2].split("=").length ==2) {
                imageWidth = Integer.parseInt(url_params[1].split("=")[1]);
                imageHeight = Integer.parseInt(url_params[2].split("=")[1]);
            }
        }

        if(imageWidth>0 && imageHeight>0){
            lp.height = new Float(imageHeight*screenWidth/imageWidth).intValue();
        }else{
            lp.height = ViewGroup.LayoutParams.MATCH_PARENT;
        }

        relative_shopInfo.setLayoutParams(lp);
        if(uriList.size()==4){
            dot_0.setVisibility(View.VISIBLE);
            dot_1.setVisibility(View.VISIBLE);
            dot_2.setVisibility(View.VISIBLE);
            dot_3.setVisibility(View.VISIBLE);
            dots.add(getView().findViewById(R.id.dot_0));
            dots.add(getView().findViewById(R.id.dot_1));
            dots.add(getView().findViewById(R.id.dot_2));
            dots.add(getView().findViewById(R.id.dot_3));
        }

        if(uriList.size()==1){
            dot_0.setVisibility(View.VISIBLE);
            dots.add(getView().findViewById(R.id.dot_0));
        }

        if(uriList.size()==2){
            dot_0.setVisibility(View.VISIBLE);
            dot_1.setVisibility(View.VISIBLE);
            dots.add(getView().findViewById(R.id.dot_0));
            dots.add(getView().findViewById(R.id.dot_1));
        }

        if(uriList.size()==3){
            dot_0.setVisibility(View.VISIBLE);
            dot_1.setVisibility(View.VISIBLE);
            dot_2.setVisibility(View.VISIBLE);
            dots.add(getView().findViewById(R.id.dot_0));
            dots.add(getView().findViewById(R.id.dot_1));
            dots.add(getView().findViewById(R.id.dot_2));
        }

        if(uriList.size()==5){
            dot_0.setVisibility(View.VISIBLE);
            dot_1.setVisibility(View.VISIBLE);
            dot_2.setVisibility(View.VISIBLE);
            dot_3.setVisibility(View.VISIBLE);
            dot_4.setVisibility(View.VISIBLE);
            dots.add(getView().findViewById(R.id.dot_0));
            dots.add(getView().findViewById(R.id.dot_1));
            dots.add(getView().findViewById(R.id.dot_2));
            dots.add(getView().findViewById(R.id.dot_3));
            dots.add(getView().findViewById(R.id.dot_4));
        }
        if(uriList.size()==6){
            dot_0.setVisibility(View.VISIBLE);
            dot_1.setVisibility(View.VISIBLE);
            dot_2.setVisibility(View.VISIBLE);
            dot_3.setVisibility(View.VISIBLE);
            dot_4.setVisibility(View.VISIBLE);
            dot_5.setVisibility(View.VISIBLE);
            dots.add(getView().findViewById(R.id.dot_0));
            dots.add(getView().findViewById(R.id.dot_1));
            dots.add(getView().findViewById(R.id.dot_2));
            dots.add(getView().findViewById(R.id.dot_3));
            dots.add(getView().findViewById(R.id.dot_4));
            dots.add(getView().findViewById(R.id.dot_5));
        }
        if(uriList.size()==7){
            dot_0.setVisibility(View.VISIBLE);
            dot_1.setVisibility(View.VISIBLE);
            dot_2.setVisibility(View.VISIBLE);
            dot_3.setVisibility(View.VISIBLE);
            dot_4.setVisibility(View.VISIBLE);
            dot_5.setVisibility(View.VISIBLE);
            dot_6.setVisibility(View.VISIBLE);
            dots.add(getView().findViewById(R.id.dot_0));
            dots.add(getView().findViewById(R.id.dot_1));
            dots.add(getView().findViewById(R.id.dot_2));
            dots.add(getView().findViewById(R.id.dot_3));
            dots.add(getView().findViewById(R.id.dot_4));
            dots.add(getView().findViewById(R.id.dot_5));
            dots.add(getView().findViewById(R.id.dot_6));
        }
        if(uriList.size()==8){
            dot_0.setVisibility(View.VISIBLE);
            dot_1.setVisibility(View.VISIBLE);
            dot_2.setVisibility(View.VISIBLE);
            dot_3.setVisibility(View.VISIBLE);
            dot_4.setVisibility(View.VISIBLE);
            dot_5.setVisibility(View.VISIBLE);
            dot_6.setVisibility(View.VISIBLE);
            dot_7.setVisibility(View.VISIBLE);
            dots.add(getView().findViewById(R.id.dot_0));
            dots.add(getView().findViewById(R.id.dot_1));
            dots.add(getView().findViewById(R.id.dot_2));
            dots.add(getView().findViewById(R.id.dot_3));
            dots.add(getView().findViewById(R.id.dot_4));
            dots.add(getView().findViewById(R.id.dot_5));
            dots.add(getView().findViewById(R.id.dot_6));
            dots.add(getView().findViewById(R.id.dot_7));
        }
        if(uriList.size()==9){
            dot_0.setVisibility(View.VISIBLE);
            dot_1.setVisibility(View.VISIBLE);
            dot_2.setVisibility(View.VISIBLE);
            dot_3.setVisibility(View.VISIBLE);
            dot_4.setVisibility(View.VISIBLE);
            dot_5.setVisibility(View.VISIBLE);
            dot_6.setVisibility(View.VISIBLE);
            dot_7.setVisibility(View.VISIBLE);
            dot_8.setVisibility(View.VISIBLE);
            dots.add(getView().findViewById(R.id.dot_0));
            dots.add(getView().findViewById(R.id.dot_1));
            dots.add(getView().findViewById(R.id.dot_2));
            dots.add(getView().findViewById(R.id.dot_3));
            dots.add(getView().findViewById(R.id.dot_4));
            dots.add(getView().findViewById(R.id.dot_5));
            dots.add(getView().findViewById(R.id.dot_6));
            dots.add(getView().findViewById(R.id.dot_7));
            dots.add(getView().findViewById(R.id.dot_8));
        }

        if(uriList.size()==10){
            dot_0.setVisibility(View.VISIBLE);
            dot_1.setVisibility(View.VISIBLE);
            dot_2.setVisibility(View.VISIBLE);
            dot_3.setVisibility(View.VISIBLE);
            dot_4.setVisibility(View.VISIBLE);
            dot_5.setVisibility(View.VISIBLE);
            dot_6.setVisibility(View.VISIBLE);
            dot_7.setVisibility(View.VISIBLE);
            dot_8.setVisibility(View.VISIBLE);
            dot_9.setVisibility(View.VISIBLE);
            dots.add(getView().findViewById(R.id.dot_0));
            dots.add(getView().findViewById(R.id.dot_1));
            dots.add(getView().findViewById(R.id.dot_2));
            dots.add(getView().findViewById(R.id.dot_3));
            dots.add(getView().findViewById(R.id.dot_4));
            dots.add(getView().findViewById(R.id.dot_5));
            dots.add(getView().findViewById(R.id.dot_6));
            dots.add(getView().findViewById(R.id.dot_7));
            dots.add(getView().findViewById(R.id.dot_8));
            dots.add(getView().findViewById(R.id.dot_9));
        }
            mViewPager = new RollViewPager(getActivity(), dots,
                    R.drawable.dot_focus, R.drawable.dot_normal,
                    new RollViewPager.OnPagerClickCallback() {
                        @Override
                        public void onPagerClick(int position) {
                                Intent intent = new Intent(getActivity(), TeMaiKaiQiangActivity.class);
                                intent.putExtra("active_id", lunboBeans.get(position).getActive_id());
                                intent.putExtra("active_desc", lunboBeans.get(position).getActive_desc());
                                intent.putExtra("active_icon", lunboBeans.get(position).getActive_icon());
                                intent.putExtra("startTime", lunboBeans.get(position).getStart_time());
                                intent.putExtra("endTime", lunboBeans.get(position).getEnd_time());
                                intent.putExtra("title", lunboBeans.get(position).getActive_right_title());
                                startActivity(intent);
                        }
                    });

//        mViewPager.setResImageIds(imageIDs);//设置本地的图片url
        mViewPager.setUriList(uriList);//设置网络图片的url

//        mViewPager.setTitle(title, titles);//不需要显示标题，可以不设置
         mViewPager.startRoll();//不调用的话不滚动
         mViewPagerLay.addView(mViewPager);
    }
    /**
     * progressDialog的展示
     */
    public void showProgress() {
        if (mProgress == null) {
            mProgress = new LoadingDialog(getActivity(),"");
            mProgress.setCancelable(true);
            mProgress.show();

        } else {
            if (mProgress.isShowing()) {
                stopProgress();
            } else {
                mProgress.show();
            }
        }
    }


    /**
     * progressDialog的消失
     */
    public void stopProgress() {
        if (mProgress != null) {
            mProgress.dismiss();
            mProgress = null;
        }
    }



    private class TeMaiAndKQHandler extends Handler {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case 1:
                    boolean isNeedCountTime = false;
                    //①：其实在这块需要精确计算当前时间
                    for (int index = 0; index < goodss.size(); index++) {
                        Goods goods = goodss.get(index);
                        long time = goods.getTime();
                        if (time > 100) {//判断是否还有条目能够倒计时，如果能够倒计时的话，延迟一秒，让它接着倒计时
                            isNeedCountTime = true;
                            goods.setTime(time - 100);
                        } else {
                            goods.setTime(0);
                            goodss.remove(index);
                            goodAdapter.notifyDataSetChanged();
                            teMaiKQHandler.sendEmptyMessageDelayed(1, 100);
                        }
                    }
                    //②：for循环执行的时间
                    goodAdapter.notifyDataSetChanged();
                    if (isNeedCountTime) {
                        //TODO 然后用1000-（②-①），就赢延迟的时间
                        teMaiKQHandler.sendEmptyMessageDelayed(1, 100);
                    }
                    break;
                case 2:
                    boolean isNeedCountTime2 = false;
                    //①：其实在这块需要精确计算当前时间
                    for (int index = 0; index < goodss.size(); index++) {
                        Goods goods = goodss.get(index);
                        long time = goods.getTime();
                        if (time > 100) {//判断是否还有条目能够倒计时，如果能够倒计时的话，延迟一秒，让它接着倒计时
                            isNeedCountTime2 = true;
                            goods.setTime(time - 100);
                        } else {
                            goods.setTime(0);
                            goodss.remove(index);
                            kaiQiangAdapter.notifyDataSetChanged();
                            teMaiKQHandler.sendEmptyMessageDelayed(2, 100);
                        }
                    }
                    //②：for循环执行的时间
                    kaiQiangAdapter.notifyDataSetChanged();
                    if (isNeedCountTime2) {
                        //TODO 然后用1000-（②-①），就赢延迟的时间
                        teMaiKQHandler.sendEmptyMessageDelayed(2, 100);
                    }
                    break;

            }
        }
    }

    //获取当前时间
    private String getNewTime(){
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
        return df.format(new Date());
    }

    /**
     * 得到时间差
     */
    private  Long getTime(String time,String time2){

        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
        try
        {
            Date d1 = df.parse(time2);
            Date d2 = df.parse(time);
            diff = d1.getTime() - d2.getTime();//这样得到的差值是微秒级别
            return diff;
        }
        catch (Exception e)
        {
        }
        return null;
    }




}
